<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class M_user extends CI_Model {
    /**
     * 继承父类
     */
    function __construct()
    {
        parent::__construct();
    }
    /**
     * 登陆模块
     * @param  [type] $user    用户编号
     * @param  [type] $password 密码
     * @param  string $classify 用户类型
     * @return [type]           [description]
     */
    public function login($user,$password,$classify='')
    {
        //老师
        if($classify=='1'){
            $query="SELECT * FROM stu_t_login WHERE no='".$user."' AND password='".$password."'";
            $result=$this->db->query($query);
        }
        //学生
        else if($classify=='2')
        {
            $query="SELECT * FROM stu_s_login WHERE no='".$user."' AND pwd='".$password."'";
            $result=$this->db->query($query);
        }
        //管理员
        else
        {
            $query="SELECT * FROM stu_admin WHERE name='".$user."' AND pwd='".$password."'";
            $result=$this->db->query($query);
        }
        return $result->result();
    }
    public function updateUser($str1=array(),$str2=array(),$param='')
    {
        $str='';
        $where='';
        foreach ($str1 as $key => $value) {
            if($key){
                $str=$str?($str." , "):$str;
                $str=$str.$key."='".$value."'";
            }
        }
        foreach ($str2 as $key => $value) {
            if($key){
                $where=$where?($where."AND"):$where;
                $where=$where.$key."='".$value."'";
            }
        }
        if($param=='1'){
            $query="UPDATE stu_t_login SET ".$str." WHERE ".$where;
        }else if($param=='2'){
            $query="UPDATE stu_s_login SET ".$str." WHERE ".$where;
        }else{
            $query="UPDATE stu_admin SET ".$str." WHERE ".$where;
        }
        return $this->db->query($query);
    }
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */